<!--
 * @Author: 李天惊 uf_lee@163.com
 * @Date: 2023-01-29 13:58:42
 * @LastEditors: 李天惊 uf_lee@163.com
 * @LastEditTime: 2023-08-03 13:20:18
 * @FilePath: \zhmc\pc\sys\src\views\UserCenter\Org\User\components\Add.vue
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved. 
-->
<script setup lang="ts">
import { PropType, reactive, ref, unref } from 'vue'
import { LeeEdit } from '@/components/Lee/Edit'
import { ucUserListAdminApi } from '@/api/uc/user'
const props = defineProps({
  data: {
    type: Object as PropType<Nullable<any>>,
    default: () => null
  }
})

const editSchema = reactive<FormSchema[]>([
  {
    field: 'user_id',
    label: '用户',
    component: 'DialogRefer',
    componentProps: {
      fixedSearch: { org_id: props.data.org_id },
      getListApi: ucUserListAdminApi,
      response: {
        count: 'count',
        data: 'data'
      },
      title: '选择所属员工（双击选择）',
      nameField: 'nickname',
      valueField: 'user_id',
      crudSchemas: [
        {
          field: 'nickname',
          label: '别名',
          fixed: 'left',
          search: {
            show: true
          }
        },
        {
          field: 'username',
          label: '用户名',
          fixed: 'left',
          search: {
            show: true
          }
        }
      ]
    },
    colProps: {
      span: 24
    }
  }
])

const leeEditRef = ref<ComponentRef<typeof LeeEdit>>()
const elFormRef = () => {
  return unref(leeEditRef)?.elFormRef
}
const getData = async () => {
  return await unref(leeEditRef)?.getFormData()
}
defineExpose({
  elFormRef,
  getData
})
</script>

<template>
  <LeeEdit ref="leeEditRef" :schema="editSchema" :data="props.data" />
</template>
